package com.spa.interfaces.massagist;

import com.spa.application.command.massagist.WithdrawApplyNewCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.massagist.MassagistWithdrawOrderDetailDTO;
import com.spa.application.dto.massagist.MessagistWithdrawListDTO;
import com.spa.application.dto.massagist.MessagistWithdrawProgressDTO;
import com.spa.application.dto.massagist.WithdrawAccountDTO;
import com.spa.application.dto.massagist.OrderListWithdrawDTO;
import com.spa.application.query.massagist.*;
import com.spa.application.service.massagist.MassagistWithdrawApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.interfaces.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@RestController
@RequestMapping("massagist/withdraw")
public class MassagistWithdrawController extends BaseController {

    @Autowired
    private MassagistWithdrawApplicationService massagistWithdrawApplicationService;

    @PostMapping("v2/apply")
    public ResponseMessage applyNew(@Validated @RequestBody WithdrawApplyNewCommand command) {
        command.validate();
        massagistWithdrawApplicationService.applyNew(command);
        return responseHelper.success();
    }

    @PostMapping("lastWithdrawAccount")
    public ResponseMessage<WithdrawAccountDTO> lastWithdrawAccount(){
        return responseHelper.success(massagistWithdrawApplicationService.lastWithdrawAccount());
    }

    @PostMapping("page")
    public ResponseMessage<PageResult<MessagistWithdrawListDTO>> page(@Validated({MessagistWithdrawQuery.QueryList.class}) @RequestBody MessagistWithdrawQuery query) throws ParseException {
        return responseHelper.success(massagistWithdrawApplicationService.page(query));
    }

    @PostMapping("withdrawOrderList")
    public ResponseMessage<PageResult<OrderListWithdrawDTO>> withdrawOrderList(@Validated @RequestBody MessagistWithdrawRecordDetailQuery query) {
        return responseHelper.success(massagistWithdrawApplicationService.withdrawOrderList(query));
    }

    @PostMapping("orderList")
    public ResponseMessage<PageResult<OrderListWithdrawDTO>> orderList(@RequestBody MassagistOrderWithdrawQuery query){
        return responseHelper.success(massagistWithdrawApplicationService.orderList(query));
    }

    @PostMapping("orderTotal")
    public ResponseMessage<Integer> orderTotal() {
        return responseHelper.success(massagistWithdrawApplicationService.orderTotal());
    }

    @PostMapping("orderDetail")
    public ResponseMessage<MassagistWithdrawOrderDetailDTO> orderDetail(@Validated @RequestBody MassagistWithdrawOrderDetailQuery query) {
        return responseHelper.success(massagistWithdrawApplicationService.orderDetail(query));
    }

    @PostMapping("progress")
    public ResponseMessage<MessagistWithdrawProgressDTO> progress(@Validated({MessagistWithdrawQuery.QueryById.class}) @RequestBody MessagistWithdrawQuery query) {
        return responseHelper.success(massagistWithdrawApplicationService.progress(query));
    }

}
